<?php

    //Listing Table Class define
    include("ClassListing.php");
    //Listing Table Class define
    include("ClassRooms.php");
	//Sub Table Class define
    include_once("ClassSub.php");
	
class ResidentialClass
{
    var $Listing;
	var $Bedrooms;
	var $Baths;
	var $Subdivision;
	var $AssociationFee;
	var $LivingArea;
	var $LotSize;
	var $Parking;
	var $Stories;
	var $YearBuilt;
	var $Heating;
	var $Cooling;
	var $Pool;
	var $InteriorFeatures;
	var $ExteriorFeatures;
	var $Style;
	var $Rooms;				/// Loop
	var $Fireplaces;
	var $Roof;
	var $Exterior;

	function AddItemFromXML( $xmlFormat )
	{
		$Array = $xmlFormat->children();

		$this->Listing = new ListingClass;
		$this->Listing->AddItemFromXML($Array[0]);	
	 	$this->Bedrooms = $Array[1];
	 	$this->Baths = new BathsClass;
		$this->Baths->AddItemFromXML($Array[2]);
	 	$this->Subdivision = $Array[3];
	 	$this->AssociationFee = new CurrencyFormatClass;
		$this->AssociationFee->AddItemFromXML($Array[4]);
		$this->LivingArea = new LivingAreaClass;
		$this->LivingArea->AddItemFromXML($Array[5]);
		$this->LotSize = new AreaRoomFormatClass;
		$this->LotSize->AddItemFromXML($Array[6]);
		$this->Parking = new ParkingClass;
		$this->Parking->AddItemFromXML($Array[7]);
		$Stories = $Array[8];	
		$YearBuilt = $Array[9];	
		$Heating = $Array[10];	
		$Cooling = $Array[11];	
		$Pool = $Array[12];	
		$InteriorFeatures = $Array[13];	
		$ExteriorFeatures = $Array[14];	
		$Style = $Array[15];		
		$this->Rooms = new RoomsClass;
		$this->Rooms->AddItemFromXML($Array[16]);	
		$Fireplaces = $Array[17];	
		$Roof = $Array[18];	
		$Exterior = $Array[19];			
	}
	
	function InsertSQL()
	{
		$strSqlCommand = "SELECT * FROM ResidentialProperty ";
		$strSqlCommand .= " WHERE Listing_idListing = '".$this->Listing->ListingID."' ";
		$result = mysql_query($strSqlCommand);
		if( !$result )
		{
			echo $this->Listing->ListingID.$strSqlCommand." Search Failed<br/>";
		}
		if( @mysql_num_rows($result) == 0)
		{	// New
			$this->Listing->InsertSQL();
			$this->Baths->InsertSQL();		
			$this->AssociationFee->InsertSQL();
			$this->LivingArea->InsertSQL();		
			$this->LotSize->InsertSQL();		
			$this->Parking->InsertSQL();		
			$this->Rooms->InsertSQL();		
			
			$strSqlCommand = "INSERT INTO ResidentialProperty( Listing_idListing, Bedrooms, ";
			$strSqlCommand .="Baths_idBaths, Subdivision, AssociationFee, LivingArea_idLivingArea, ";
			$strSqlCommand .="LotSize, Parking_idParking, Stories, YearBuilt, Heating, Cooling, ";
			$strSqlCommand .="Pool, InteriorFeatures, ExteriorFeatures, Style, Rooms_idRooms, ";
			$strSqlCommand .="Fireplaces, Roof, Exterior) ";
			$strSqlCommand .= "VALUES( '".$this->Listing->ListingID."', ";
			$strSqlCommand .= "'".$this->Bedrooms."', ";
			$strSqlCommand .= "'".$this->Baths->ID."', ";
			$strSqlCommand .= "'".$this->Subdivision."', ";
			$strSqlCommand .= "'".$this->AssociationFee->ID."', ";
			$strSqlCommand .= "'".$this->LivingArea->ID."', ";
			$strSqlCommand .= "'".$this->LotSize->ID."', ";
			$strSqlCommand .= "'".$this->Parking->ID."', ";
			$strSqlCommand .= "'".$this->Stories."', ";
			$strSqlCommand .= "'".$this->YearBuilt."', ";
			$strSqlCommand .= "'".$this->Heating."', ";
			$strSqlCommand .= "'".$this->Cooling."', ";
			$strSqlCommand .= "'".$this->Pool."', ";
			$strSqlCommand .= "'".$this->InteriorFeatures."', ";
			$strSqlCommand .= "'".$this->ExteriorFeatures."', ";
			$strSqlCommand .= "'".$this->Style."', ";
			$strSqlCommand .= "'".$this->Rooms->ID."', ";
			$strSqlCommand .= "'".$this->Fireplaces."', ";
			$strSqlCommand .= "'".$this->Roof."', ";
			$strSqlCommand .= "'".$this->Exterior."') ";
				
			if(!mysql_query($strSqlCommand))
			{
				//echo $this->Listing->ListingID.$strSqlCommand." Insert Failed<br/>";
			}
			$id = mysql_insert_id();
		}
/*		
		else
		{	// Modify
			$rowMF = @mysql_fetch_array($result);

			$strSqlCommand =  "UPDATE ResidentialProperty SET ";
			$strSqlCommand =  "Bedrooms='"		.$this->Bedrooms	."', ";
			$strSqlCommand .= "Subdivision='"	.$this->Subdivision		."', ";
			$strSqlCommand .= "Stories='".$this->Stories."', ";
			$strSqlCommand .= "YearBuilt='".$this->YearBuilt."', ";
			$strSqlCommand .= "Heating='".$this->Heating."', ";
			$strSqlCommand .= "Cooling='".$this->Cooling."', ";
			$strSqlCommand .= "Pool='".$this->Pool."', ";
			$strSqlCommand .= "InteriorFeatures='".$this->InteriorFeatures."', ";
			$strSqlCommand .= "ExteriorFeatures='".$this->ExteriorFeatures."', ";
			$strSqlCommand .= "Style='".$this->Style."', ";
			$strSqlCommand .= "Fireplaces='".$this->Fireplaces."', ";
			$strSqlCommand .= "Roof='".$this->Roof."', ";
			$strSqlCommand .= "Exterior='".$this->Exterior."' ";
			$strSqlCommand .= "' WHERE idResidentialProperty = ".$rowLand["idResidentialProperty"];
			if(!mysql_query($strSqlCommand))
			{
				echo $this->Listing->ListingID. $strSqlCommand." Modify Failed<br/>";
			}
			
			$this->Listing->ModifySQL(  );
			$this->Baths->ModifySQL( $rowLand["Baths_idBaths"] );
			$this->AssociationFee->ModifySQL( $rowLand["AssociationFee"] );
			$this->LivingArea->ModifySQL( $rowLand["LivingArea_idLivingArea"] );
			$this->LotSize->ModifySQL( $rowLand["LotSize"] );
			$this->Parking->ModifySQL( $rowLand["Parking_idParking"] );
			$this->Rooms->ModifySQL( $rowLand["Rooms_idRooms"] );
		}
*/
	}
}

?>